
export const mixins = {
	data() {
		return {};
	},
	computed: {},
	created() {},
	mounted() {},

	methods: {
		navto(url) {
			console.log(url)
			uni.navigateTo({
				url
			})
		},
		call(mobile, id, type) {
			uni.makePhoneCall({
				phoneNumber: '10086', //仅为示例
				complete() {
					let maintest = plus.android.runtimeMainActivity();
					let Contexttest = plus.android.importClass("android.content.Context");
					let telephonyManager = plus.android.importClass(
						"android.telephony.TelephonyManager");
					let telManager = plus.android.runtimeMainActivity().getSystemService(
						Contexttest
						.TELEPHONY_SERVICE);
					let receiver = plus.android.implements(
						'io.dcloud.android.content.BroadcastReceiver', {
							onReceive: function(Contexttest, intent) {
								plus.android.importClass(intent);
								console.log(intent.getAction());
								// let telephonyManager = plus.android.importClass("android.telephony.TelephonyManager");
								// let telephonyManager=plus.android.runtimeMainActivity().getSystemService(Contexttest.TELEPHONY_SERVICE);
								let phonetype = telManager.getCallState();
								let phoneNumber = intent.getStringExtra(
									telephonyManager
									.EXTRA_INCOMING_NUMBER);
								switch (phonetype) {
									case 0:
										//添加记录
										if (type == 1) {
											sale.createCustomerRecord({
												"type": "2",
												"customer_id": id
											}).then(res=>{
												console.log(res)
											})
										}
										if (type == 2) {
											sale.editTask({
												id,
												status:2
											}).then(res=>{
												console.log(res)
											})
										}
										break;
									case 1:
			
										break;
									case 2:
			
										break;
								}
							}
						});
					let IntentFilter = plus.android.importClass(
						'android.content.IntentFilter');
					let filter = new IntentFilter();
					filter.addAction(telephonyManager.ACTION_PHONE_STATE_CHANGED);
					maintest.registerReceiver(receiver, filter);
				}
			});
		},
		back() {
			uni.navigateBack()
		},
		copy(text) {
			uni.setClipboardData({
				data: text,
				success: function() {
					uni.$u.toast('复制成功')
				}
			});
		},
		preview(urls, current) {
			let url = []
			urls.map(t => {
				url.push(this.URL(t))
			})
			uni.previewImage({
				urls: url,
				current
			});
		},
	},
	computed: {
		URL() {
			return (url) => {
				if (url?.includes('https:') || url?.includes('data:image/') || url?.includes('http:')) {
					return url
				} else {
					return 'http://dn.fuliaoxx.com' + url
				}


				// return url.includes('https:') ? url : this.$BASE_URL + url
			}
		},

		/**
		 * 根据出生日期算出年龄
		 */
		getAge() {
			return (strBirthday) => {
				var returnAge;
				var strBirthdayArr = strBirthday.split("-");
				var birthYear = strBirthdayArr[0];
				var birthMonth = strBirthdayArr[1];
				var birthDay = strBirthdayArr[2];

				var d = new Date();
				var nowYear = d.getFullYear();
				var nowMonth = d.getMonth() + 1;
				var nowDay = d.getDate();

				if (nowYear == birthYear) {
					returnAge = 0; //同年 则为0岁
				} else {
					var ageDiff = nowYear - birthYear; //年之差
					if (ageDiff > 0) {
						if (nowMonth == birthMonth) {
							var dayDiff = nowDay - birthDay; //日之差
							if (dayDiff < 0) {
								returnAge = ageDiff - 1;
							} else {
								returnAge = ageDiff;
							}
						} else {
							var monthDiff = nowMonth - birthMonth; //月之差
							if (monthDiff < 0) {
								returnAge = ageDiff - 1;
							} else {
								returnAge = ageDiff;
							}
						}
					} else {
						returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天
					}
				}
				return returnAge; //返回周岁年龄
			}
		}


	}
};